package controllers;

import java.io.IOException;
import java.util.ArrayList;

import javax.xml.parsers.ParserConfigurationException;

import models.OntologyModel;
import objects.ConceptList;

import org.xml.sax.SAXException;

import views.MainPanel;
import views.ViewOntology;
import controllers.listeners.ontology.OntologyNavigationActionListener;
import controllers.listeners.ontology.OntologyTableMouseListener;

/* Initializes Ontology UI and listeners */
public class OntologyModuleController {
	
	private ViewOntology view;
	
	public OntologyModuleController(MainPanel mp) throws ParserConfigurationException, SAXException, IOException {
		initializeView(mp);
	}
	
	public void initializeView(MainPanel mp) throws ParserConfigurationException, SAXException, IOException {
		/* Get data from model */
		ArrayList<ConceptList> ontologyList = OntologyModel.getOntology();
		
		/* Initialize UI */
		view = new ViewOntology();
		
		/** Initialize listener **/
		
		OntologyNavigationActionListener navListener = new OntologyNavigationActionListener();
		OntologyTableMouseListener tableListener = new OntologyTableMouseListener();
		
		navListener.setView(view);
		tableListener.setView(view);
		
		tableListener.setMainPanel(mp);
		
		navListener.setConceptList(ontologyList);
		
		/* Initialize event sources */
		view.addNavListener(navListener);
		view.addTableListener(tableListener);
		
		/* Populate tables */
		if (ontologyList != null && ontologyList.size() > 0) {
			view.loadOntology(ontologyList.get(0));
			view.setLabelsForChooser(ontologyList);
		}
		
		/* Set UI visible */
		view.setVisible(true);
	}
	
}
